package metalink.admin;

import java.util.ArrayList;

import vo.DepartmentDetailsVo;
import vo.mixed.CourseListVo;
import vo.mixed.DepartmentListVo;
import model.admin.GetBatchListMo;
import model.admin.GetListsMo;
import model.admin.ModifyCoursesMo;
import model.admin.ModifyDepartmentsMo;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ModifyDepartmentDetails extends ActionSupport {
	int batch_id;
	int degree_id;
	int course_id;
	int department_id;
	String department_name;
	String description;
	int start_year;
	String value="";
	ArrayList<DepartmentListVo>department_list = new ArrayList<DepartmentListVo>();
	ArrayList<CourseListVo> department_course_list=new ArrayList<CourseListVo>();
	ArrayList<CourseListVo> course=new ArrayList<CourseListVo>();
	ArrayList<Integer> year_list;
	String course_selected;
	ArrayList<String> course_list;
	
	public int getCourse_id() {
		return course_id;
	}

	public void setCourse_id(int course_id) {
		this.course_id = course_id;
	}

	public ArrayList<CourseListVo> getCourse() {
		return course;
	}

	public void setCourse(ArrayList<CourseListVo> course) {
		this.course = course;
	}

	public ArrayList<CourseListVo> getDepartment_course_list() {
		return department_course_list;
	}

	public void setDepartment_course_list(
			ArrayList<CourseListVo> department_course_list) {
		this.department_course_list = department_course_list;
	}

	public ArrayList<DepartmentListVo> getDepartment_list() {
		return department_list;
	}

	public void setDepartment_list(ArrayList<DepartmentListVo> department_list) {
		this.department_list = department_list;
	}

	public int getDegree_id() {
		return degree_id;
	}

	public void setDegree_id(int degree_id) {
		this.degree_id = degree_id;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getCourse_selected() {
		return course_selected;
	}

	public void setCourse_selected(String course_selected) {
		this.course_selected = course_selected;
	}

	public ArrayList<Integer> getYear_list() {
		return year_list;
	}

	public void setYear_list(ArrayList<Integer> year_list) {
		this.year_list = year_list;
	}

	public int getDepartment_id() {
		return department_id;
	}

	public ArrayList<String> getCourse_list() {
		return course_list;
	}

	public void setCourse_list(ArrayList<String> course_list) {
		this.course_list = course_list;
	}

	public int getBatch_id() {
		return batch_id;
	}

	public void setBatch_id(int batch_id) {
		this.batch_id = batch_id;
	}

	public int getStart_year() {
		return start_year;
	}

	public void setStart_year(int start_year) {
		this.start_year = start_year;
	}

	public void setDepartment_id(int department_id) {
		this.department_id = department_id;
	}

	public String getDepartment_name() {
		return department_name;
	}

	public void setDepartment_name(String department_name) {
		this.department_name = department_name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
/*
	public String updateBatchDepartmentDetails() {
		System.out.println("HiiiiiR");
		ModifyDepartmentsMo single_object = new ModifyDepartmentsMo();
		System.out.println(department_id + " dept id \t");
		DepartmentDetailsVo department_details = new DepartmentDetailsVo();
		department_details.setDepartment_id(getDepartment_id());
		System.out.println(department_details.getDepartment_id() + " set \n");
		department_details.setDepartment_name(getDepartment_name());
		department_details.setDescription(getDescription());
		if (single_object.updateDepartmentDetails(department_details))
			return "success";
		else
			return "error";
	}
*/
/*
	public String deleteBatchDepartmentDetails() {
		ModifyDepartmentsMo deleteObj = new ModifyDepartmentsMo();
		deleteObj.deleteDepartmentDetails(batch_id, department_id);
		return SUCCESS;
	}
*/
	public String addBatchDepartmentDetails() {
		GetListsMo list = new GetListsMo();
	//	department_list=list.getDepartmentList();
//		setDepartment_list(list.getDepartmentList());
		setYear_list(list.GetYearList());
		return SUCCESS;
	}

	public String submitBatchDepartmentDetails() {
		ModifyDepartmentsMo single_obj = new ModifyDepartmentsMo();
		single_obj.addBatchDepartmentDetails(department_name, description,
				batch_id, start_year,"BatchDepartment");
		System.out.println("batch id  " + batch_id + "\t start year "
				+ start_year);
		return SUCCESS;
	}

	public String addDepartmentDetails() {
		ModifyDepartmentsMo m = new ModifyDepartmentsMo();
		DepartmentDetailsVo department = new DepartmentDetailsVo();
		department.setDepartment_name(department_name);
		department.setDescription(description);
		department.setStart_year(start_year);
		m.addNewDepartment(department,"AddDepartment");
		return SUCCESS;
	}
///Execute Starts from Here
	public String execute() {
		ModifyDepartmentsMo depmo = new ModifyDepartmentsMo();
		GetBatchListMo batchmo = new GetBatchListMo();
		
		if(value.contentEquals("deletedepart")){
		
		try {
			depmo.deleteDepartmentDetails(batch_id, department_id,value);
			department_list= batchmo.getDepartmentList(batch_id, degree_id,department_id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}else if(value.contentEquals("editdep")){
			try {
				department_list= batchmo.getDepartmentList(batch_id, degree_id,department_id);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if(value.contentEquals("updatedep")){
			
			try {
				depmo.updateDepartmentDetails(department_name, description, department_id,value);
				department_list= batchmo.getDepartmentList(0,0,0);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if(value.contentEquals("viewcourse")){
			try {
				department_course_list=batchmo.getBatchCourseList(0, department_id);
				course=batchmo.getDepartmentCourseList(department_id);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if (value.contentEquals("updatedecourse")){
			try {
				depmo.updateDepartmentCourse(department_id, course_id,value);
				department_course_list=batchmo.getBatchCourseList(0, department_id);
				course=batchmo.getDepartmentCourseList(department_id);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return SUCCESS;
	}
//Execute Ends Here
	public String deleteDepartmentDetails() {
		ModifyDepartmentsMo deleteObj = new ModifyDepartmentsMo();
		deleteObj.deleteDepartmentDetails(0, department_id,"deletedepartment");
		return SUCCESS;
	}
/*
	public String addNewDepartmentCourse() {
		GetListsMo m = new GetListsMo();
		setCourse_list(m.getAllCourses());
		return SUCCESS;
	}
*/
	public String submitNewDepartmentCourse() {

		ModifyCoursesMo m= new ModifyCoursesMo();
		CourseListVo c= new CourseListVo();
		m.addDepartmentCourseDetails(department_id, course_selected,"AddDepartmentcourse");
		return SUCCESS;
	}
}
